import java.util.Arrays;
import java.util.Scanner;

/**
 * 【程序29】   
 * 题目：求一个3*3矩阵对角线元素之和
 */
public class test29 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] array = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print("请输入元素：");
                array[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < 3; i++) {
            System.out.println(Arrays.toString(array[i]));
        }
        int leftSum = 0;
        int rightSum = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == j) {
                    leftSum = leftSum + array[i][j];
                }
                if ((i + j) == 2){
                    rightSum = rightSum + array[i][j];
                }
            }
        }
        System.out.println("左对角线和为：" + leftSum);
        System.out.println("右对角线和为：" + rightSum);
    }
}
